package com.ruoyi.web.controller.index;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.controller.tool.DateTimeUtils;
import org.apache.commons.lang3.RandomUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions;
import java.util.*;

@RestController
@RequestMapping("/system/index")
public class index1 {
    @Autowired
    private RedisTemplate<String, String> redisTemplate;
   // private  String imagePath = "/www/wwwroot/default/image/img.png"; // 图片路径
  //  private  String imagePath2 = "/www/wwwroot/default/image/image.png"; // 图片路径
    private  String imagePath = "D:\\project\\20250318\\img.png";
    private  String imagePath2 ="D:\\project\\20250318\\image.png";
    private  String imagePath1 = "/www/wwwroot/default/image/7-3.png"; // 图片路径
    @GetMapping(value = "/getImage")
    public ResponseEntity<Resource> getImagePath() throws IOException, WriterException {
        String[] dateStrList = DateTimeUtils.getNowDateStr(DateTimeUtils.DATE_FORMAT_YYYY_MM_DD).split("-");
        String timeStr = DateTimeUtils.getDateTimeToString(new Date(),DateTimeUtils.DATE_FORMAT_YYYYMMDD);
        String[] dateList = DateTimeUtils.getNowDateStr(DateTimeUtils.DATETIME_FORMAT_HH_MM).split(":");


        BufferedImage originalImage = ImageIO.read(new File(imagePath));
        BufferedImage processedImage = new BufferedImage(originalImage.getWidth(), originalImage.getHeight(), BufferedImage.TYPE_INT_RGB);
        Graphics2D g2d = processedImage.createGraphics();
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        // 绘制原始图片
        g2d.drawImage(originalImage, 0, 0, null);
        // 设置绘图属性
        g2d.setFont(new Font("宋体", Font.PLAIN, 25)); // 字体大小颜色等
        g2d.setColor(Color.darkGray); // 字体颜色
        // 设置字体粗细
        float strokeWidth = 0.0f; // 更细的字体，可以使用更细的线条
        BasicStroke stroke = new BasicStroke(strokeWidth);
        g2d.setStroke(stroke);


        //String imagePath2 = "/Users/apple/IdeaProjects/demo/zichan/ruoyi-admin/src/main/resources/image/image.png";
        BufferedImage originalImage1 = ImageIO.read(new File(imagePath2));
        BufferedImage processedImage1 = new BufferedImage(originalImage1.getWidth(), originalImage1.getHeight(), BufferedImage.TYPE_INT_RGB);
        Graphics2D g2d1 = processedImage1.createGraphics();
        g2d1.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2d1.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        // 绘制原始图片
        g2d1.drawImage(originalImage1, 0, 0, null);
        // 设置绘图属性
        g2d1.setFont(new Font("宋体", Font.PLAIN, 17)); // 字体大小颜色等
        g2d1.setColor(Color.darkGray); // 字体颜色
        // 设置字体粗细
        float strokeWidth1 = 0.0f; // 更细的字体，可以使用更细的线条
        BasicStroke stroke1 = new BasicStroke(strokeWidth1);
        g2d1.setStroke(stroke1);

       // http://localhost:8087/system/index/getImage1?initx1=130&inity1=160&addx1=100&addx2=80&initxc=720&initx3=783&inity3=680&addx3=90&addx4=65&initx5=1000&addx5=70&initxqr=1135&inityqr=3&qrsize=100


        int  initx1=200 ;int inity1=259 ;int addx1=143 ;int addx2=115 ;int initxc=1050 ;int initx3=1165 ;int inity3=965 ;int addx3=125 ;int addx4=90 ;int initx5=1480 ;int addx5=98 ;int initxqr=1655 ;int inityqr=43 ;int qrsize=130;
        draw1( g2d,dateStrList, timeStr ,  dateList, initx1,inity1 , addx1 , addx2 , initxc , initx3 , inity3 , addx3 , addx4 , initx5 , addx5 , initxqr , inityqr , qrsize);
        ///////////////////////
        initx1=115 ;  inity1=155 ;  addx1=90 ;  addx2=65 ;  initxc=625 ;  initx3=700 ;  inity3=592 ;  addx3=75 ;  addx4=60 ;  initx5=895 ;  addx5=55 ;  initxqr=987 ;  inityqr=12 ;  qrsize=90;

        draw2( g2d1,dateStrList, timeStr ,  dateList, initx1,inity1 , addx1 , addx2 , initxc , initx3 , inity3 , addx3 , addx4 , initx5 , addx5 , initxqr , inityqr , qrsize);

        String outputPath = "/www/wwwroot/default/image2/"+ UUID.randomUUID() +".png"; // 输出图片路径
        // outputPath ="D:\\project\\20250318\\"+ UUID.randomUUID() +".png";
        ImageIO.write(processedImage, "png", new File(outputPath));// 输出图片
        g2d.dispose();

        String outputPath1 = "/www/wwwroot/default/images/111.png"; // 输出图片路径
       // outputPath1 = "D:\\project\\dy\\image.png";
        ImageIO.write(processedImage1, "png", new File(outputPath1));// 输出图片
        g2d1.dispose();
        uploadImg(outputPath1);
        Path directory = Paths.get("/www/wwwroot/default/images"); // 替换为你的目录路径
        try {
            // 设置权限为777
            Set<PosixFilePermission> perms = PosixFilePermissions.fromString("rwxrwxrwx");
            // 遍历目录下的所有文件并设置权限
            Files.walk(directory)
                    .forEach(path -> {
                        try {
                            Files.setPosixFilePermissions(path, perms);
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    });
        } catch (IOException e) {
            e.printStackTrace();
        }
        // 加载图片资源
        Resource resource = loadResource(outputPath);
        // 构建响应
        return ResponseEntity.ok()
                .contentType(MediaType.IMAGE_PNG)
                .body(resource);
    }


    @GetMapping(value = "/getImage1")
    public ResponseEntity<Resource> getImage1( int initx1, int inity1, int addx1, int addx2,
                                                  int initxc,
                                                  int initx3,int inity3,int addx3,int addx4,
                                                  int initx5,int addx5,
                                                  int initxqr,int inityqr,
                                                  int qrsize

    ) throws IOException, WriterException {

        String[] dateStrList = DateTimeUtils.getNowDateStr(DateTimeUtils.DATE_FORMAT_YYYY_MM_DD).split("-");
        String timeStr = DateTimeUtils.getDateTimeToString(new Date(),DateTimeUtils.DATE_FORMAT_YYYYMMDD);
        String[] dateList = DateTimeUtils.getNowDateStr(DateTimeUtils.DATETIME_FORMAT_HH_MM).split(":");


        BufferedImage originalImage = ImageIO.read(new File(imagePath));
        BufferedImage processedImage = new BufferedImage(originalImage.getWidth(), originalImage.getHeight(), BufferedImage.TYPE_INT_RGB);
        Graphics2D g2d = processedImage.createGraphics();
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        // 绘制原始图片
        g2d.drawImage(originalImage, 0, 0, null);
        // 设置绘图属性
        g2d.setFont(new Font("宋体", Font.BOLD, 19)); // 字体大小颜色等
        g2d.setColor(Color.darkGray); // 字体颜色
        // 设置字体粗细
        float strokeWidth = 0.0f; // 更细的字体，可以使用更细的线条
        BasicStroke stroke = new BasicStroke(strokeWidth);
        g2d.setStroke(stroke);
        draw1(g2d,dateStrList,timeStr,dateList,
                initx1,  inity1,  addx1,  addx2,
                initxc,
                initx3, inity3, addx3, addx4,
                initx5, addx5,
                initxqr, inityqr,  qrsize
        );

        String outputPath = "/www/wwwroot/default/image2/"+ UUID.randomUUID() +".png"; // 输出图片路径
        outputPath ="D:\\project\\20250318\\"+ UUID.randomUUID() +".png";
        ImageIO.write(processedImage, "png", new File(outputPath));// 输出图片
        g2d.dispose();

        // 加载图片资源
        Resource resource = loadResource(outputPath);
        // 构建响应
        return ResponseEntity.ok()
                .contentType(MediaType.IMAGE_PNG)
                .body(resource);

    }


    @GetMapping(value = "/getImage2")
    public ResponseEntity<Resource> getImagePath( int initx1, int inity1, int addx1, int addx2,
                                                  int initxc,
                                                  int initx3,int inity3,int addx3,int addx4,
                                                  int initx5,int addx5,
                                                  int initxqr,int inityqr, int qrsize

    ) throws IOException, WriterException {
        BufferedImage originalImage1 = ImageIO.read(new File(imagePath2));
        BufferedImage processedImage1 = new BufferedImage(originalImage1.getWidth(), originalImage1.getHeight(), BufferedImage.TYPE_INT_RGB);
        Graphics2D g2d1 = processedImage1.createGraphics();
        g2d1.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2d1.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        // 绘制原始图片
        g2d1.drawImage(originalImage1, 0, 0, null);
        // 设置绘图属性
        g2d1.setFont(new Font("宋体", Font.PLAIN, 17)); // 字体大小颜色等
        g2d1.setColor(Color.darkGray); // 字体颜色
        // 设置字体粗细
        float strokeWidth1 = 0.0f; // 更细的字体，可以使用更细的线条
        BasicStroke stroke1 = new BasicStroke(strokeWidth1);
        g2d1.setStroke(stroke1);
        String[] dateStrList = DateTimeUtils.getNowDateStr(DateTimeUtils.DATE_FORMAT_YYYY_MM_DD).split("-");
        String timeStr = DateTimeUtils.getDateTimeToString(new Date(),DateTimeUtils.DATE_FORMAT_YYYYMMDD);
        String[] dateList = DateTimeUtils.getNowDateStr(DateTimeUtils.DATETIME_FORMAT_HH_MM).split(":");
        draw2(g2d1,dateStrList,timeStr,dateList,
                initx1,  inity1,  addx1,  addx2,
                initxc,
                initx3, inity3, addx3, addx4,
                initx5, addx5,
                initxqr, inityqr,  qrsize
        );

        String outputPath = "/www/wwwroot/default/image2/"+ UUID.randomUUID() +".png"; // 输出图片路径
         outputPath ="D:\\project\\20250318\\"+ UUID.randomUUID() +".png";
        ImageIO.write(processedImage1, "png", new File(outputPath));// 输出图片
        g2d1.dispose();

        // 加载图片资源
        Resource resource = loadResource(outputPath);
        // 构建响应
        return ResponseEntity.ok()
                .contentType(MediaType.IMAGE_PNG)
                .body(resource);



    }

    public void draw1( Graphics2D g2d,String[] dateStrList, String timeStr , String[] dateList,

                               int initx1, int inity1, int addx1, int addx2,
                               int initxc,
                               int initx3, int inity3, int addx3, int addx4,
                               int initx5, int addx5,
                               int initxqr, int inityqr, int qrsize
                       ) throws WriterException {
        /*int initx1=200;
        int inity1=259;
        int addx1=143;
        int addx2=115;
        int initxc=1050;
        int initx3=1165;
        int inity3=965;
        int addx3=125;
        int addx4=90;
        int initx5=1480;
        int addx5=98;
        int initxqr=1165;
        int inityqr=965;
        int qrsize = 130;*/

        int x = initx1;
        int y = inity1;
        int i=0;
        for (String time:dateStrList) {
            g2d.drawString(time, x, y);// 在图片上的坐标位置绘制文字
            if(i==0){
                x=x+addx1;
            }else {
                x=x+addx2;
            }

            i++;
        }



        x=initxc;
        timeStr = "C"+timeStr+RandomUtils.nextInt(0,999999);
        g2d.drawString(timeStr, x, y);// 在图片上的坐标位置绘制文字

       // 绘制年月日

        x=initx3;
        y=inity3;
        int i1=0;
        for (String time:dateStrList) {
            g2d.drawString(time, x, y);// 在图片上的坐标位置绘制文字
            if(i1==0){
                x=x+addx3;
            }else {
                x=x+addx4;
            }
            i1++;
        }

        // 绘制十分

        x=initx5;
        for (String time:dateList) {
            g2d.drawString(time, x, y);// 在图片上的坐标位置绘制文字
            x=x+addx5;
        }
        //二维码

        String text = "https://www.sczyjk.top/index2.html";
        QRCodeWriter qrCodeWriter = new QRCodeWriter();
        Map<EncodeHintType, Object> hints = new HashMap<>();
        hints.put(EncodeHintType.MARGIN, 0); // 设置边框为0
        hints.put(EncodeHintType.ERROR_CORRECTION, com.google.zxing.qrcode.decoder.ErrorCorrectionLevel.H);
        BitMatrix bitMatrix = qrCodeWriter.encode(text, BarcodeFormat.QR_CODE,qrsize, qrsize);
        BufferedImage bufferedImage = MatrixToImageWriter.toBufferedImage(bitMatrix);
        x=initxqr;
        y=inityqr;
        g2d.drawImage(bufferedImage,x, y,null);// 在图片上的坐标位置绘制文字
    }


    public void draw2( Graphics2D g2d1,String[] dateStrList, String timeStr , String[] dateList,
      int initx1, int inity1, int addx1, int addx2,
                       int initxc,
                       int initx3, int inity3, int addx3, int addx4,
                       int initx5, int addx5,
                       int initxqr, int inityqr, int qrsize

    ) throws WriterException {

        int x1 = initx1;
        int y1 = inity1;

        int i=0;
        for (String time:dateStrList) {
            g2d1.drawString(time, x1, y1);// 在图片上的坐标位置绘制文字
            if(i==0){
                x1=x1+addx1;
            }else {
                x1=x1+addx2;
            }

            i++;
        }

        timeStr = "C"+timeStr+RandomUtils.nextInt(0,999999);
        g2d1.drawString(timeStr, initxc, inity1);// 在图片上的坐标位置绘制文字

        // 绘制年月日
        int i1=0;
        x1=initx3;
        y1=inity3;
        for (String time:dateStrList) {
            g2d1.drawString(time, x1, y1);// 在图片上的坐标位置绘制文字
            if(i1==0){
                x1=x1+addx3;
            }else {
                x1=x1+addx4;
            }
            i1++;
        }

        // 绘制十分
        x1=initx5;
        for (String time:dateList) {
            g2d1.drawString(time, x1, y1);// 在图片上的坐标位置绘制文字
            x1=x1+addx5;
        }

        //二维码
        //二维码
        String text = "https://www.sczyjk.top/index2.html";
        QRCodeWriter qrCodeWriter = new QRCodeWriter();
        Map<EncodeHintType, Object> hints = new HashMap<>();
        hints.put(EncodeHintType.MARGIN, 0); // 设置边框为0
        hints.put(EncodeHintType.ERROR_CORRECTION, com.google.zxing.qrcode.decoder.ErrorCorrectionLevel.H);
        BitMatrix bitMatrix = qrCodeWriter.encode(text, BarcodeFormat.QR_CODE, qrsize, qrsize,hints);
        BufferedImage bufferedImage = MatrixToImageWriter.toBufferedImage(bitMatrix);
        x1=initxqr;
        y1=inityqr;
        g2d1.drawImage(bufferedImage,x1, y1,null);// 在图片上的坐标位置绘制文字
    }

    @PostMapping(value = "/getWelcome")
    public AjaxResult getWelcome(){
        return AjaxResult.success("","赵**，您好!");
    }

    @PostMapping(value = "/login")
    public AjaxResult login(@RequestBody LoginDTO loginDTO){
        String key = "LoginKey";
        String value = "";
        if(loginDTO.getUserName().equals("16789678654")&&loginDTO.getPassWord().equals("as123456")){
            value = UUID.randomUUID().toString();
            redisTemplate.opsForValue().set(key,value);
        }else {
            return AjaxResult.error("登陆失败");
        }
        return AjaxResult.success("",value);
    }


    @GetMapping(value = "/getImage/{image}")
    public ResponseEntity<Resource> getImagePath2(@PathVariable String image) throws IOException {
        // 加载图片资源
        Resource resource = loadResource("/www/wwwroot/default/images/"+image);
        // 构建响应
        return ResponseEntity.ok()
                .contentType(MediaType.IMAGE_PNG)
                .body(resource);

    }

    @GetMapping(value = "/getImage1/{image}")
    public ResponseEntity<Resource> getImage1(@PathVariable String image) throws IOException {
        // 加载图片资源
        Resource resource = loadResource("/www/wwwroot/default/image/"+image);
        // 构建响应
        return ResponseEntity.ok()
                .contentType(MediaType.IMAGE_PNG)
                .body(resource);

    }

    @PostMapping(value = "/getName")
    public AjaxResult getName(){
        Map<String,Object> map = new HashMap<>();
        map.put("name","赵善杰,450204199201281013");
        map.put("local","通州区玉桥西路26号院2号楼1层1单元102");
        return AjaxResult.success("",map);
    }





    private Resource loadResource(String imagePath) {
        // 实现加载图片资源的逻辑，这里可以是文件系统、类路径、网络等不同位置
        // 这里的示例是加载文件系统中的图片
        return new FileSystemResource(imagePath);
    }





    private static final int QR_CODE_SIZE = 130;

    public static void main(String[] args) throws WriterException, IOException {
        String imagePath = "/Users/apple/IdeaProjects/demo/zichan/ruoyi-admin/src/main/resources/image/img.png";

       imagePath = "D:\\project\\img.png";


        String[] dateStrList = DateTimeUtils.getNowDateStr(DateTimeUtils.DATE_FORMAT_YYYY_MM_DD).split("-");
        int x = 200;
        int y = 280;
        BufferedImage originalImage = ImageIO.read(new File(imagePath));
        BufferedImage processedImage = new BufferedImage(originalImage.getWidth(), originalImage.getHeight(), BufferedImage.TYPE_INT_RGB);
        Graphics2D g2d = processedImage.createGraphics();
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        // 绘制原始图片
        g2d.drawImage(originalImage, 0, 0, null);
        // 设置绘图属性
        g2d.setFont(new Font("宋体", Font.PLAIN, 27)); // 字体大小颜色等
        g2d.setColor(Color.darkGray); // 字体颜色
        // 设置字体粗细
        float strokeWidth = 0.0f; // 更细的字体，可以使用更细的线条
        BasicStroke stroke = new BasicStroke(strokeWidth);
        g2d.setStroke(stroke);


        String imagePath2 = "/Users/apple/IdeaProjects/demo/zichan/ruoyi-admin/src/main/resources/image/image.png";
        imagePath2 ="D:\\project\\image.png";
        BufferedImage originalImage1 = ImageIO.read(new File(imagePath2));
        BufferedImage processedImage1 = new BufferedImage(originalImage1.getWidth(), originalImage1.getHeight(), BufferedImage.TYPE_INT_RGB);
        Graphics2D g2d1 = processedImage1.createGraphics();
        g2d1.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2d1.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        // 绘制原始图片
        g2d1.drawImage(originalImage1, 0, 0, null);
        // 设置绘图属性
        g2d1.setFont(new Font("宋体", Font.PLAIN, 19)); // 字体大小颜色等
        g2d1.setColor(Color.darkGray); // 字体颜色
        // 设置字体粗细
        float strokeWidth1 = 0.0f; // 更细的字体，可以使用更细的线条
        BasicStroke stroke1 = new BasicStroke(strokeWidth1);
        g2d1.setStroke(stroke1);
        int x1 = 108;
        int y1 = 155;

        int i=0;
        for (String time:dateStrList) {
            g2d.drawString(time, x, y);// 在图片上的坐标位置绘制文字
            g2d1.drawString(time, x1, y1);// 在图片上的坐标位置绘制文字
            if(i==0){
                x=x+166;
                x1=x1+90;
            }else {
                x=x+120;
                x1=x1+70;
            }

            i++;
        }
        x=1120;
        x1=630;
        String timeStr = DateTimeUtils.getDateTimeToString(new Date(),DateTimeUtils.DATE_FORMAT_YYYYMMDD);
        timeStr = "C"+timeStr+RandomUtils.nextInt(0,999999);
        g2d.drawString(timeStr, x, y);// 在图片上的坐标位置绘制文字
        g2d1.drawString(timeStr, x1, y1);// 在图片上的坐标位置绘制文字

        x=1250;
        y=1087;
        int i1=0;
        x1=700;
        y1=590;
        for (String time:dateStrList) {
            g2d.drawString(time, x, y);// 在图片上的坐标位置绘制文字
            g2d1.drawString(time, x1, y1);// 在图片上的坐标位置绘制文字
            if(i1==0){
                x=x+150;
                x1=x1+73;
            }else {
                x=x+90;
                x1=x1+60;
            }
            i1++;
        }

        String[] dateList = DateTimeUtils.getNowDateStr(DateTimeUtils.DATETIME_FORMAT_HH_MM).split(":");
        x=1600;
        x1=890;
        for (String time:dateList) {
            g2d.drawString(time, x, y);// 在图片上的坐标位置绘制文字
            g2d1.drawString(time, x1, y1);// 在图片上的坐标位置绘制文字
            x=x+98;
            x1=x1+62;
        }
        //二维码
        String text = "http://image.gwery.cn:88/index.html";
        QRCodeWriter qrCodeWriter = new QRCodeWriter();
        Map<EncodeHintType, Object> hints = new HashMap<>();
        hints.put(EncodeHintType.MARGIN, 0); // 设置边框为0
        hints.put(EncodeHintType.ERROR_CORRECTION, com.google.zxing.qrcode.decoder.ErrorCorrectionLevel.H);
        BitMatrix bitMatrix = qrCodeWriter.encode(text, BarcodeFormat.QR_CODE, 98, 98,hints);
        BufferedImage bufferedImage = MatrixToImageWriter.toBufferedImage(bitMatrix);
        x=1800;
        y=50;

        x1=986;
        y1=3;
        g2d.drawImage(bufferedImage,x, y,null);// 在图片上的坐标位置绘制文字
        g2d1.drawImage(bufferedImage,x1, y1,null);// 在图片上的坐标位置绘制文字

//        String outputPath = "/Users/apple/IdeaProjects/demo/zichan/ruoyi-admin/src/main/resources/image2/111.png"; // 输出图片路径
//        ImageIO.write(processedImage, "png", new File(outputPath));// 输出图片
//        g2d.dispose();

        String outputPath1 = "/Users/apple/IdeaProjects/demo/zichan/ruoyi-admin/src/main/resources/image2/222.png"; // 输出图片路径
         outputPath1 = "D:\\project\\外面20250317\\zichan(1)\\zichan\\ruoyi-admin\\src\\main\\resources\\image\\111.png";
        ImageIO.write(processedImage1, "png", new File(outputPath1));// 输出图片
        g2d1.dispose();

    }

    public static  void  uploadImg(String imagePath){
        RestTemplate restTemplate = new RestTemplate();

        String url = "https://www.sczyjk.top/prod-api/common/uploadTest";
        //  String url = "http://localhost:8080/common/uploadTest";

        // 设置请求头
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.MULTIPART_FORM_DATA);

        // 构建请求体
        MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
        body.add("file", new FileSystemResource(imagePath)); // 本地图片路径

        // 发送请求
        HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
        ResponseEntity<String> response = restTemplate.postForEntity(url, requestEntity, String.class);

        // 输出结果
        System.out.println("响应状态: " + response.getStatusCode());
        System.out.println("响应内容: " + response.getBody());
    }


//    public static void main(String[] args) throws IOException {
//        String imagePath = "/Users/apple/IdeaProjects/demo/zichan/test/WechatIMG114.jpg";
//
//        int x = 70;
//        int y = 385;
//        BufferedImage originalImage = ImageIO.read(new File(imagePath));
//        BufferedImage processedImage = new BufferedImage(originalImage.getWidth(), originalImage.getHeight(), BufferedImage.TYPE_INT_RGB);
//        Graphics2D g2d = processedImage.createGraphics();
//        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
//        g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
//        // 绘制原始图片
//        g2d.drawImage(originalImage, 0, 0, null);
//        // 设置绘图属性
//        g2d.setFont(new Font("宋体", Font.PLAIN, 16)); // 字体大小颜色等
//        g2d.setColor(Color.GRAY); // 字体颜色
//        // 设置字体粗细
//        float strokeWidth = 0.0f; // 更细的字体，可以使用更细的线条
//        BasicStroke stroke = new BasicStroke(strokeWidth);
//        g2d.setStroke(stroke);
//
//        String outputPath1 = "/Users/apple/IdeaProjects/demo/zichan/test/111.jpg"; // 输出图片路径
//        g2d.drawString("无", x, y);// 在图片上的坐标位置绘制文字
//        ImageIO.write(processedImage, "jpg", new File(outputPath1));// 输出图片
//        g2d.dispose();
//
//    }

}
